package com.greensecurity.sim.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.Date;
import java.util.List;

@Entity
@AllArgsConstructor
@With
@Table(name = "user")
@Data
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull(message = "用户ID不能为空")
    private Long userId;

    private String userName;

    private String realName;

    private String password;

    private String phone;

    private String email;
//  用户头像路径
    private String userPhotoUrl;

//    创建时间
    @CreatedDate
    private Date createTime;

//    修改时间
    @LastModifiedDate
    private Date updateTime;
//    规则
    @ManyToMany
    private List<Role> role;

    private int photoDistinguishNum;

    @OneToMany(cascade=CascadeType.ALL)
    private List<GreenLand> greenLands;

    @OneToMany(cascade=CascadeType.ALL)
    private List<Green> green;

    public User(){
        this.updateTime =new Date();
    }
}
